var R = false, F = false, P = false;//用于验证菜单


$(function(){
	$("#addressId").val(-1); 
	var ops = $("#address");
	
	$.ajax({
		type:"POST",
		url:"order.do?method=2",
		datatype:"json",
		async:false,
		sussess:function(data){
			var addrs = data.addrs;
			appendOps(addrs);
			ops.change(function(){
				fillForm(addrs,$(this).val());
			});
		}
	});
	
	
	function appendOps(addrs){
		for(var i = 0; i < addrs.length;i++){
			ops.append("<option value'"+i+"'>"+i+":"+addrs[i].fullAddress.substr(0,6)+"...</option>");
		}
	}
	
	function fillForm(addrs,index){
		if(index == -1){
			$("#receiveName").val('');
			$("#fullAddress").val('');
			$("#postalCode").val('');
			$("#phone").val('');
			$("#mobile").val('');
			$("#addressId").val('-1');
			return;
		}
		P = true;
		R = true;
		F = true;
		
		$("#nameValidMsg>span").html('');
		$("#addressValidMsg>span").html('');
		$("#receiveName").val(addrs[index].receiveName);
		$("#fullAddress").val(addrs[index].fullAddress);
		$("#postalCode").val(addrs[index].postalCode);
		$("#phone").val(addrs[index].phone);
		$("#mobile").val(addrs[index].mobile);
		
		$("#addressId").val(addrs[index].id);
	}
});
$(function(){
	alert("kkk");
	var R = false, F = false, P = false;
	$("#btnClientRegister").click(function(){
		if(F && P && R){
			return true;
		}else{
			return false;
		}
	});
	
	$("#receiveName").blur(function(){
		R=false;
		var val=$(this).val();
		var info=$("#name\\.info");
		info.html("");
		if(val==""){
			info.text("收件人不能为空");
		}else{
			R=true;
			info.html("<img src='./images/my/ajax_ok.png'/>");	
		}
	});
	
	$("#fullAddress").blur(function(){
		F=false;
		var val=$(this).val();
		var info=$("#address\\.info");
		info.html("");
		if(val==""){
			info.text("收信地址不能为空");
		}else{
			F=true;
			info.html("<img src='./images/my/ajax_ok.png'/>");	
		}
	});
	
	$("#postalCode").blur(function(){
		P=false;
		var val=$(this).val();
		var info=$("#code\\.info");
		info.html("");
		if(val==""){
			info.text("邮政编码不能为空");
		}else{
			P=true;
			info.html("<img src='./images/my/ajax_ok.png'/>");	
		}
	});
})